//
//  BCUploadImageRequest.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/12/28.
//  Copyright © 2018 guoshikeji. All rights reserved.
//

#import "BCUploadImageRequest.h"

@implementation BCUploadImageRequest

- (HttpRequestMethod)requestMethod {
    return POST;
}
- (NSString *)relativelyUrl {
    return V1_Upload;
}

- (NSMutableArray *)uploadDatas {//{"data": , "fileName": "", "name" : "name" mimeType : "mimeType"}
    if (self.uploadImage) {
        NSData *imageData = UIImageJPEGRepresentation(self.uploadImage, 0.5);
        NSString *fileName = @"image";
        NSString *name = @"image";
        NSString *mimeType = @"image/png";
        return [NSMutableArray arrayWithArray:@[@{@"data":imageData,
                                                  @"fileName":fileName,
                                                  @"name":name,
                                                  @"mimeType":mimeType
                                                  }]];
    }
    return nil;
}


- (BOOL)success:(NSURLSessionDataTask *)task data:(id)obj {
    BOOL success = [super success:task data:obj];
    if (success) {
        BCUploadImageResponse *resp = [BCUploadImageResponse yy_modelWithJSON:obj];
        if (self.requestSuccessed) {
            self.requestSuccessed(resp, nil);
        }
    }
    return success;
}

@end
